<td width="727"><table width="727" border="0" cellspacing="0" cellpadding="0">
                                <tr> 
                                  <td width="727" height="47" valign="top" background="img/bar_blue.jpg"><table width="727" border="0" cellspacing="0" cellpadding="0">
                                      <tr> 
                                        <td width="10" height="47">&nbsp;</td>
                                        <td width="23" height="47"><img src="img/bar_flblue.jpg" width="23" height="23"></td>
                                        <td width="10" height="47">&nbsp;</td>
                                        <td height="47" class="tahoma12W"><strong> 
                                          <?php echo $lang['CONTENT_TITLE_TRANSACTION']; ?></strong></td>
                                      </tr>
                                    </table></td>
                                </tr>
                                <tr> 
                                  <td width="727" height="6" valign="top"><img src="img/spec_blank.gif" width="10" height="7"></td>
                                </tr>
                                <tr> 
                                  <td width="727" height="878" valign="top"  ><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                      <tr> 
                                        <td height="601" valign="top"  ><table width="100%" height="878" border="0" cellpadding="0" cellspacing="0">
                                            <tr> 
                                              <td height="763" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                 
                                                  <tr> 
                                                    <td width="10">&nbsp;</td>
                                                    <td align="left" valign="top" class="arial12G66">
														<?php
															if(isset($_POST['amount'])){
																$amount = $_POST['amount'];
															}
															if(isset($_POST['orderid'])){
																$orderid = $_POST['orderid'];
															}
															if(isset($_POST['appcode'])){
																$appcode = $_POST['appcode'];
															}
															if(isset($_POST['tranID'])){
																$tranID = $_POST['tranID'];
															}
															if(isset($_POST['domain'])){
																$domain = $_POST['domain'];
															}
															if(isset($_POST['status'])){
																$status = $_POST['status'];
															}
															if(isset($_POST['currency'])){
																$currency = $_POST['currency'];
															}
															if(isset($_POST['paydate'])){
																$paydate = $_POST['paydate'];
															}
															if(isset($_POST['channel'])){
																$channel = $_POST['channel'];
															}
															if(isset($_POST['skey'])){
																$skey = $_POST['skey'];
															}
															//print('<pre>');
																//print_r($_POST);
															//print('</pre>');
	
																$successUpdate = false;
																//get from define
																$vkey = VKEY;
																 
																$key0 = md5($tranID.$orderid.$status.$domain.$amount.$currency); 
																$key1 = md5($paydate.$domain.$key0.$appcode.$vkey); 
																//echo '<br /> $skey : '.$skey; 
																//echo '<br /> $key1 : '.$key1; 
																//echo '<br /> $key0 : '.$key0; 
																
																
																if( $skey == $key1 ) {
																	//echo '<br /> masuk sini --- invalid transaction '; 
																	if ( $status == "00" ){ 
																		//echo '<br />  However success transaction '; 
																		$statuspayment = STATUSPAYMENTPAID;
																		$status_transaction = STATUSPAYMENTPAID_TRANS;
																		$updTrans= "UPDATE transaction SET  amount='$amount', 
																					appcode='$appcode', tranid='$tranID', domain='$domain',
																					status_nbepay = '$status', currency ='$currency', paydate='$paydate',
																					channel='$channel', serialkey='$skey', status_payment='$statuspayment',vcode='$key1',
																					status_transaction='$status_transaction',modified_date=now() where order_no='$orderid'";
																		$resultTrans = $db->sql_query($updTrans);
																		
																		$log = "Payment Completed";
																		
																		if ($resultTrans){	
																			$successUpdate = true;
																			unset($_SESSION['cart']); 
																			unset($_SESSION['locationPrice']); 
																			unset($_SESSION['cartConfirmCheckout']);
																		}
																	  
																	} else if( $status == "11" ) { 
																			$log = "Payment Failed";
																			if($orderid!=""){
																				$statuspayment = STATUSPAYMENTFAILURE;
																				$status_transaction = STATUSPAYMENTFAILURE_TRANS;
																				$updTrans= "UPDATE transaction SET  amount='$amount', 
																							appcode='$appcode', tranid='$tranID', domain='$domain',
																							status_nbepay = '$status', currency ='$currency', paydate='$paydate',
																							channel='$channel', serialkey='$skey', status_payment='$statuspayment',vcode='$key1',
																							status_transaction='$status_transaction',modified_date=now() where order_no='$orderid'";
																				$resultTrans = $db->sql_query($updTrans);
																					
																				if ($resultTrans){	 
																					$successUpdate = false;
																				}
																			}
																	} else if( $status == "22" ) { 
																			$log = "Payment Failed";
																			if($orderid!=""){
																				$statuspayment = STATUSPAYMENTTIMEOUT;
																				$status_transaction = STATUSPAYMENTTIMEOUT_TRANS;
																				$updTrans= "UPDATE transaction SET  amount='$amount', 
																							appcode='$appcode', tranid='$tranID', domain='$domain',
																							status_nbepay = '$status', currency ='$currency', paydate='$paydate',
																							channel='$channel', serialkey='$skey', status_payment='$statuspayment',vcode='$key1',
																							status_transaction='$status_transaction',modified_date=now() where order_no='$orderid'";
																				$resultTrans = $db->sql_query($updTrans);
																					
																				if ($resultTrans){	 
																					$successUpdate = false;
																				}
																			}
																	}
																}else{
																	//echo '<br />  Invalid transaction '; 
																	$invalid = '1';
																	if ( $status == "00" ){ 
																		$statuspayment = STATUSPAYMENTPAID;
																		$status_transaction = STATUSPAYMENTPAID_TRANS;
																		$updTrans= "UPDATE transaction SET  amount='$amount', 
																					appcode='$appcode', tranid='$tranID', domain='$domain',
																					status_nbepay = '$status', currency ='$currency', paydate='$paydate',
																					channel='$channel', serialkey='$skey', status_payment='$statuspayment',vcode='$key1',
																					status_transaction='$status_transaction', isInvalid='$invalid', modified_date=now() where order_no='$orderid'";
																		$resultTrans = $db->sql_query($updTrans);
																		
																		$qTrans = "SELECT * from transaction where order_no = '$orderid' ";
																		$rTrans = $db->sql_list($qTrans);
																		
																		$log = "Payment Completed";
																		
																		if ($resultTrans){	
																			$successUpdate = true;
																			unset($_SESSION['cart']); 
																			unset($_SESSION['locationPrice']); 
																			unset($_SESSION['cartConfirmCheckout']);
																		}
																	  
																	} else if( $status == "11" ) { 
																			$log = "Payment Failed";
																			if($orderid!=""){
																				$statuspayment = STATUSPAYMENTFAILURE;
																				$status_transaction = STATUSPAYMENTFAILURE_TRANS;
																				$updTrans= "UPDATE transaction SET  amount='$amount', 
																							appcode='$appcode', tranid='$tranID', domain='$domain',
																							status_nbepay = '$status', currency ='$currency', paydate='$paydate',
																							channel='$channel', serialkey='$skey', status_payment='$statuspayment',vcode='$key1',
																							status_transaction='$status_transaction', isInvalid='$invalid', modified_date=now() where order_no='$orderid'";
																				$resultTrans = $db->sql_query($updTrans);
																					
																				if ($resultTrans){	 
																					$successUpdate = false;
																				}
																			}
																	} else if( $status == "22" ) { 
																			$log = "Payment Failed";
																			if($orderid!=""){
																				$statuspayment = STATUSPAYMENTTIMEOUT;
																				$status_transaction = STATUSPAYMENTTIMEOUT_TRANS;
																				$updTrans= "UPDATE transaction SET  amount='$amount', 
																							appcode='$appcode', tranid='$tranID', domain='$domain',
																							status_nbepay = '$status', currency ='$currency', paydate='$paydate',
																							channel='$channel', serialkey='$skey', status_payment='$statuspayment',vcode='$key1',
																							status_transaction='$status_transaction', isInvalid='$invalid', modified_date=now() where order_no='$orderid'";
																				$resultTrans = $db->sql_query($updTrans);
																					
																				if ($resultTrans){	 
																					$successUpdate = false;
																				}
																			}
																	}
																}
																if($orderid != null){
																	$qTrans = "SELECT * from transaction where order_no = '$orderid' ";
																	$rTrans = $db->sql_list($qTrans);
																	
																	$transaction_id = $rTrans['id'];
																	$addressId = $rTrans['shipping_address_id'];
																	$type_log = "Payment";
																	$log_desc = json_encode($_POST);
																	$cTransLog= "INSERT INTO transaction_log(transaction_id,type_log, log, log_desc,created_date) 
																		VALUES 
																	($transaction_id,'$type_log', '$log','$log_desc', NOW())";
																	$rTransLog = $db->sql_query($cTransLog);
																}
																if($successUpdate == true){
																	$qTrans = "SELECT * from transaction where order_no = '$orderid' ";
																	$rTrans = $db->sql_list($qTrans);
																	
																	$qTransItems = "Select p.* from transaction t, purchaseproduct p where t.id = p.transaction_id and t.order_no = '$orderid'";
																	$rTransItems = $db->sql_fetch($qTransItems);
					
																	echo '<div id="cartDiv" >';
																	echo '<h4 class="arial11G66">'.$lang['CONTENT_TRANS_COMPLETED'].'. '.$lang['CONTENT_TRANS_COMPLETED_INFO'];
																	echo '<br />'.$lang['CONTENT_TRANS_COMPLETED_INFO2'];
																	echo '<br /> </h4>';
																	?>
																	<table width="100%" align="left" border="0" cellspacing="0" cellpadding="0">
																		<tr>
																			<td width="20%" class="tahoma11G"><?php echo $lang['FORM_TRANS_DATEPAID'];  ?></td>
																			<td width="1%"> : </td>
																			<td class="tahoma11G"><?php echo $paydate; ?></td>
																		</tr>
																		<tr>
																			<td colspan="3" style="height:5px"></td>
																		</tr>
																		<tr>
																			<td width="30%" class="tahoma11G"><?php echo $lang['FORM_TRANS_ORDERNO'];  ?></td>
																			<td width="5%"> : </td>
																			<td class="tahoma11G"><?php echo $orderid; ?></td>
																		</tr>
																		<tr>
																			<td colspan="3" style="height:5px"></td>
																		</tr>
																	</table>
																	<br />
																	<br /><br />
																	<?php 																	
																	echo '<table width="100%"  cellspacing="0" cellpadding="0" style="border-collapse: collapse; border: 1px solid #CCCCCC;">
																			<tr bgcolor="#F1F3EB" height="25">
																						<td width="50px" align="center" class="arial11P" style="border: 1px solid #CCCCCC;">'.$lang['FORM_TRANS_BIL'].'
																						</td>
																						<td  align="center" class="arial11P" style="border: 1px solid #CCCCCC;">'.$lang['FORM_TRANS_PRODUCT'].'
																						</td>
																						<td width="70px" align="center" class="arial11P" style="border: 1px solid #CCCCCC;">'.$lang['FORM_TRANS_QTY'].'
																						</td>
																						<td width="80px" align="center" class="arial11P" style="border: 1px solid #CCCCCC;">'.$lang['FORM_TRANS_TOTAL_ITEMS'].'
																						</td>
																						<td width="80px" align="center" class="arial11P" style="border: 1px solid #CCCCCC;">'.$lang['FORM_TRANS_TOTAL_WEIGHT'].'
																						</td>
																			</tr>';
																	$num =0;
																	foreach ($rTransItems as $i) {
																		$sql = "SELECT * FROM item WHERE id = '$i[item_id]'";
																		$rCheck= $db->sql_total($sql);
																		$rItem= $db->sql_list($sql);
																		if($rCheck <> 0){
																			$num++;
																			echo '	
																				<tr>
																					<td width="50px" align="center" style="border: 1px solid #CCCCCC;" class="arial11P">
																						'.$num.'
																					</td>
																					<td  align="left" style="border: 1px solid #CCCCCC;">
																						<table width="100%" border="0" cellspacing="0" cellpadding="0">
																							<tr> 
																								<td align="left" class="arial11P"> 
																									<div style="margin:4px; border:1px solid #CCCCCC;"> 
																										<img src="'.IMAGEITEM.$rItem['image'].'"  width="87" height="68"  >
																									</div>
																								</td>
																								<td width="10">&nbsp;</td>
																								<td valign="top" width="100%">
																									<table width="100%" border="0" cellspacing="0" cellpadding="0">
																										<tr> 
																											<td height=2></td>
																										</tr>
																										<tr> 
																											<td class="arial11P"><strong><a href="product_detail.php?id='.$rItem[id].'" >'.$rItem['name'].'</a></strong></td>
																										</tr>
																										<tr> 
																											<td height="3" valign="top"><img src="img/spec_blank.gif" width="10" height="3"></td>
																										</tr>
																										<tr> 
																											<td class="arial10G660">KOD 
																												'.$rItem['kod'].'</td>
																										</tr>
																										<tr> 
																											<td height="3" valign="top"><img src="img/spec_blank.gif" width="10" height="3"></td>
																										</tr>
																										<tr> 
																											<td class="arial11P"><strong>'.$lang['FORM_PRICE'].'  
																												RM'.$rItem[$priceLocation].'/Unit</strong>
																											</td>
																										</tr>
																										<tr> 
																											<td height="3" valign="top"><img src="img/spec_blank.gif" width="10" height="3"></td>
																										</tr>
																										<tr> 
																											<td class="arial11P"><strong>'.$lang['FORM_WEIGHT'].'
																												'.$rItem['weight'].'KG/Unit</strong>
																											</td>
																										</tr>
																									</table>
																								</td>
																							</tr>
																						</table>
																					</td>
																					<td  align="center" style="border: 1px solid #CCCCCC;" class="arial11P">'.$i[quantity].'
																					</td>
																					<td  align="center" style="border: 1px solid #CCCCCC;" class="arial11P">RM'.$i[totalprice].'
																					</td>
																					<td  align="center" style="border: 1px solid #CCCCCC;" class="arial11P">'.$i[totalweight].'KG
																					</td>
																				</tr>';
																		}
																	}
																	echo '		<tr bgcolor="#FFF380" height="25">
																					<td colspan="2"  align="right" style="border: 1px solid #CCCCCC;" class="arial11Pbold">'.$lang['FORM_TRANS_TOTAL_ALLITEMS'].' &nbsp;&nbsp;
																					</td>
																					<td  colspan="3" align="left" style="border: 1px solid #CCCCCC;" class="arial11Pbold"> &nbsp;&nbsp; RM'.sprintf("%01.2f", $rTrans[items_price]).'
																					
																					</td>
																				</tr>';
																	echo '		<tr bgcolor="#FFF380" height="25">
																					<td colspan="2"  align="right" style="border: 1px solid #CCCCCC;" class="arial11Pbold">'.$lang['FORM_TRANS_TOTAL_ALLWEIGHT'].' &nbsp;&nbsp;
																					</td>
																					<td  colspan="3" align="left" style="border: 1px solid #CCCCCC;" class="arial11Pbold"> &nbsp;&nbsp; RM'.sprintf("%01.2f", $rTrans[postage_price]).' for '.$rTrans[total_weight].'KG
																					
																					</td>
																				</tr>';
																	echo '			<tr bgcolor="#FFF380" height="25">
																					<td colspan="2"  align="right" style="border: 1px solid #CCCCCC;" class="arial11Pbold">'.$lang['FORM_TRANS_TOTAL_ALL'].' &nbsp;&nbsp;
																					</td>
																					<td  colspan="3"  align="left"  class="arial11Pbold" style="border: 1px solid #CCCCCC; font-size:14;"> &nbsp;&nbsp; RM'.sprintf("%01.2f", $rTrans[amount]).'
																					
																					</td>
																				</tr>';
																	echo '	</table>';
																	echo ' </div>';
																	
																	?>
																	<?php
																	    $QAddr = "SELECT * from address where id = '$addressId'";
																		$rAddr = $db->sql_list($QAddr);
																	?>
																	<fieldset>
																	<legend class="tahoma11G" style="font-weight:bold; font-size:14px;"><span><?php echo $lang['CONTENT_ADDRESS_INFO'];  ?></span></legend>
																	<table width="500" align="left" border="0" cellspacing="0" cellpadding="0">
																		<tr>
																			<td width="20%" class="tahoma11G"><?php echo $lang['FORM_NAME']; ?></td>
																			<td width="1%"> : </td>
																			<td class="tahoma11G"><input class="tahoma11G" type="text" name="nama"  readonly
																				value="<?php echo $rAddr['nama']; ?>" size="40" ></td>
																		</tr>
																		<tr>
																			<td colspan="3" style="height:5px"></td>
																		</tr>
																		<tr>
																			<td width="30%" class="tahoma11G"><?php echo $lang['FORM_PHONE']; ?></td>
																			<td width="5%"> : </td>
																			<td class="tahoma11G"><input class="tahoma11G" type="text" name="notel" readonly
																				value="<?php echo $rAddr['notel']; ?>" size="40" ></td>
																		</tr>
																		<tr>
																			<td colspan="3" style="height:5px"></td>
																		</tr>
																		<tr>
																			<td width="30%" class="tahoma11G"><?php echo $lang['FORM_ADDRESS']; ?></td>
																			<td width="5%"> : </td>
																			<td class="tahoma11G" >
																			
																				<textarea style="overflow:hidden; width:264px;"
																					rows="5"  name="ship_address" id="ship_address" readonly><?php echo $rAddr['address']; ?></textarea>
																			</td>
																		</tr>
																		<tr>
																			<td colspan="3" style="height:5px"></td>
																		</tr>
																		<tr>
																			<td width="30%" class="tahoma11G"><?php echo $lang['FORM_POSKOD']; ?></td>
																			<td width="5%"> : </td>
																			<td class="tahoma11G"><input type="text" name="ship_poskod" 
																				value="<?php echo $rAddr['poskod']; ?>" size="40" readonly></td>
																		</tr>
																		<tr>
																			<td colspan="3" style="height:5px"></td>
																		</tr>
																		<tr>
																			<td width="30%" class="tahoma11G"><?php echo $lang['FORM_CITY']; ?></td>
																			<td width="5%"> : </td>
																			<td class="tahoma11G"><input type="text" name="ship_city" 
																				value="<?php echo $rAddr['city']; ?>" size="40" readonly></td>
																		</tr>
																		<tr>
																			<td colspan="3" style="height:5px"></td>
																		</tr>
																		<tr>
																			<td width="30%" class="tahoma11G"><?php echo $lang['FORM_STATE']; ?></td>
																			<td width="5%"> : </td>
																			<td class="tahoma11G">
																				<select name="ship_state"  size="1" style="width:276px;" disabled>
																					<?php $Qstate2= "select * from states  order by state asc";
																						  $stateResult2 = $db->sql_fetch($Qstate2);
																						  
																						  foreach($stateResult2 as $c){
																								if($rAddr['state_id'] > 0){
																									if($rAddr['state_id'] ==  $c['id']){
																										echo" <option value='". $c[id]."' selected>". $c[state]."</option>";
																									}else{
																										echo" <option value='". $c[id]."'>". $c[state]."</option>";
																									}
																								}else{
																									echo" <option value='". $c[id]."'>". $c[state]."</option>";
																								}
																						  }
																						?>
																				</select>
																			</td>
																		</tr>
																		<tr>
																			<td colspan="3" style="height:5px"></td>
																		</tr>
																		<tr>
																			<td width="30%" class="tahoma11G"><?php echo $lang['FORM_COUNTRY']; ?></td>
																			<td width="5%"> : </td>
																			<td class="tahoma11G" >
																				<select name="ship_country"  size="1" style="width:276px;" disabled>
																					<?php $Qcountry2= "select * from countries where country_name = 'Malaysia' order by country_name asc";
																						  $countryResult2 = $db->sql_fetch($Qcountry2);
																						  
																						  foreach($countryResult2 as $c){
																								if($rAddr['country_id'] > 0){
																									if($rAddr['country_id'] ==  $c['id']){
																										echo" <option value='". $c[id]."' selected>". $c[country_name]."</option>";
																									}else{
																										echo" <option value='". $c[id]."'>". $c[country_name]."</option>";
																									}
																								}else if($c['country_code'] == 'MY'){
																									echo" <option value='". $c[id]."' selected>". $c[country_name]."</option>";
																								}else{
																									echo" <option value='". $c[id]."'>". $c[country_name]."</option>";
																								}
																								
																						  }
																						?>
																				</select>
																			</td>
																		</tr>
																		<tr>
																			<td colspan="3" style="height:5px"></td>
																		</tr>
																	</table>
																	</fieldset>
																	<?php
																
																}else {
																//Transaction Failed!!!!!!
																?>
																<table width="100%" align="left" border="0" cellspacing="0" cellpadding="0">
																		<tr>
																			<td width="20%" ><?php echo $lang['CONTENT_TRANSACTION_STATUS']; ?></td>
																			<td width="1%"> : </td>
																			<td ><?php echo $lang['CONTENT_TRANSACTION_STATUS_FAILED']; ?></td>
																		</tr>
																		<tr>
																			<td colspan="3" style="height:5px"></td>
																		</tr>
																		<tr>
																			<td colspan="3" style="height:5px"><?php echo $lang['CONTENT_TRANSACTION_STATUS_FAILED_INFO']; ?></td>
																		</tr>
																	</table>
																<?php
																}
														
														?>
                                                    </td>
                                                    <td width="10">&nbsp;</td>
                                                  </tr>
                                                  <tr> 
												  
                                                    <td width="10" height="10"></td>
                                                    <td height="10"></td>
                                                    <td width="10" height="10"></td>
                                                  </tr>
                                                </table></td>
												
                                            </tr>
                                          </table></td>
                                      </tr>
                                    </table></td>
                                </tr>
                              </table>